

const Buff = require('./buff');
const { game: gameConfig } = require('./config');

class VsSoldier {
    constructor(index) {
        this.deadTick = 0;
        this.index = index;
        this.buff = false;
    }
    isBuff(type) {
        return this.buff && this.buff.type === type;
    }
    isBuffOf(type, role) {
        return this.buff && this.buff.type === type && this.buff.role === role;
    }
    hasBuff() {
        return !!this.buff;
    }
    buffTime() {
        return this.buff && this.buff.time || 0;
    }
    clearBuff() {
        this.buff = false;
    }
    setBuff(type, role) {
        this.buff = {
            type: type,
            role: role,
            time: +Date.now()
        }
    }
    canKill() {
        if (this.buff) {
            return Buff[this.buff.type] && Buff[this.buff.type].kill ? Buff[this.buff.type].kill() : true;
        } else {
            return true;
        }
    }
    dead() {
        this.deadTick = 1;
    }
    isDie() {
        return this.deadTick > 0;
    }
    get data() {
        return {
            index: this.index,
            deadTick: this.deadTick,
            buff: this.buff && this.buff.type
        }
    }
}

module.exports = VsSoldier;